<%@ page import="org.bson.Document" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.mongodb.BasicDBObject" %>
<%@ page import="com.mongodb.client.*" %>
<%@ page import="javax.print.Doc" %>
<%@ page import="com.mongodb.client.result.DeleteResult" %>
<%@ page import="java.util.Arrays" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查看学生</title>
</head>
<body>
    <%
    String sno=request.getParameter("sno");
    MongoClient conn = MongoClients.create("mongodb://g08:" + URLEncoder.encode("abc@8") + "@mongo.zhledu.cn:27017/g08");
    MongoDatabase g08 = conn.getDatabase("g08");
    MongoCollection<Document> student = g08.getCollection("student");

    String snos[] =sno.split(",");
/*    Document query=new Document("sno",new Document("$in",Arrays.asList(snos)));
    DeleteResult result= student.deleteOne(query);*/
    int deleteNums=0;
    for(String s:snos)
    {
    Document query=new Document("sno",s);
    DeleteResult result= student.deleteOne(query);
    deleteNums+=result.getDeletedCount();
    }
    conn.close();
    if(snos.length==deleteNums){
        out.print("删除成功，2秒钟后跳转到列表页");
        response.setHeader("refresh","2;URL=index.jsp");
    }else{
        out.print("删除失败，2秒钟后跳转到列表页");
        response.setHeader("refresh","2;URL=index.jsp");
    }




%>
